package com.xgure.controller.admin;

import com.xgure.dto.ShopAddDTO;
import com.xgure.dto.ShopUpdateDTO;
import com.xgure.pojo.Shop;
import com.xgure.result.Result;
import com.xgure.service.ShopService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/admin/shop")
public class ShopController {

    @Resource
    private ShopService shopService;

    /**
     * 添加新的店铺
     *
     */
    @PostMapping("/new")
    public Result addNewShop(@RequestBody ShopAddDTO shopAddDTO) {
        log.info("添加新的店铺：{}", shopAddDTO);
        shopService.addNewShop(shopAddDTO);
        return Result.success();
    }

    /**
     * 获取店铺信息
     *
     */
    @GetMapping("/info")
    public Result<Shop> info(String shopId) {
        log.info("获取店铺信息{}", shopId);
        Shop shop = shopService.getShopInfo(shopId);
        return Result.success(shop);
    }

    /**
     * 添加店铺头像
     *
     */
    @PostMapping("/avatar")
    public Result<String> avatar(MultipartFile file) {
        shopService.addAvatar(file);
        return Result.success();
    }

    /**
     * 更新店铺信息并返回更新后的信息
     *
     */
    @PutMapping("/update")
    public Result<Shop> update(@RequestBody ShopUpdateDTO shopUpdateDTO) {
        Shop shop = shopService.update(shopUpdateDTO);
        // TODO 当前方法不能修改avatar，后期实现
        return Result.success(shop);
    }

}
